Allow NULL for message_format, as described in the docs and as worked
authorOwen Taylor <otaylor@redhat.com>
Wed, 29 Oct 2003 20:43:58 +0000 (20:43 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Wed, 29 Oct 2003 20:43:58 +0000 (20:43 +0000)
Wed Oct 29 15:40:26 2003  Owen Taylor  <otaylor@redhat.com>

        * gtk/gtkmessagedialog.c (gtk_message_dialog_new/
        gtk_message_dialog_new_with_format): Allow NULL
        for message_format, as described in the docs and
        as worked previously. (#125759, Richard Hult)

        * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup):
        Use g_markup_vprintf_escaped() to escape argumetns.

        * gtk/gtkmessagedialog.[ch]: Add gtk_message_dialog_set_markup()
        so there is some way to set literal markup.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkmessagedialog.c
gtk/gtkmessagedialog.h

index b7b1a4ec2ed77ef87f45bc6e0c38b2afdc84748a..d5fbaef2634f5f3fdd3f84dee1d09f5057fc3e95 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Wed Oct 29 15:40:26 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new/
+       gtk_message_dialog_new_with_format): Allow NULL
+       for message_format, as described in the docs and
+       as worked previously. (#125759, Richard Hult)
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup):
+       Use g_markup_vprintf_escaped() to escape argumetns.
+
+       * gtk/gtkmessagedialog.[ch]: Add gtk_message_dialog_set_markup()
+       so there is some way to set literal markup.
+
 Wed Oct 29 15:01:32 2003  Owen Taylor  <otaylor@redhat.com>
  
        * gdk/x11/gdkimage-x11.c (_gdk_x11_copy_to_image): Move
index b7b1a4ec2ed77ef87f45bc6e0c38b2afdc84748a..d5fbaef2634f5f3fdd3f84dee1d09f5057fc3e95 100644 (file)
@@ -1,3 +1,16 @@
+Wed Oct 29 15:40:26 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new/
+       gtk_message_dialog_new_with_format): Allow NULL
+       for message_format, as described in the docs and
+       as worked previously. (#125759, Richard Hult)
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup):
+       Use g_markup_vprintf_escaped() to escape argumetns.
+
+       * gtk/gtkmessagedialog.[ch]: Add gtk_message_dialog_set_markup()
+       so there is some way to set literal markup.
+
 Wed Oct 29 15:01:32 2003  Owen Taylor  <otaylor@redhat.com>
  
        * gdk/x11/gdkimage-x11.c (_gdk_x11_copy_to_image): Move
index b7b1a4ec2ed77ef87f45bc6e0c38b2afdc84748a..d5fbaef2634f5f3fdd3f84dee1d09f5057fc3e95 100644 (file)
@@ -1,3 +1,16 @@
+Wed Oct 29 15:40:26 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new/
+       gtk_message_dialog_new_with_format): Allow NULL
+       for message_format, as described in the docs and
+       as worked previously. (#125759, Richard Hult)
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup):
+       Use g_markup_vprintf_escaped() to escape argumetns.
+
+       * gtk/gtkmessagedialog.[ch]: Add gtk_message_dialog_set_markup()
+       so there is some way to set literal markup.
+
 Wed Oct 29 15:01:32 2003  Owen Taylor  <otaylor@redhat.com>
  
        * gdk/x11/gdkimage-x11.c (_gdk_x11_copy_to_image): Move
index b7b1a4ec2ed77ef87f45bc6e0c38b2afdc84748a..d5fbaef2634f5f3fdd3f84dee1d09f5057fc3e95 100644 (file)
@@ -1,3 +1,16 @@
+Wed Oct 29 15:40:26 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new/
+       gtk_message_dialog_new_with_format): Allow NULL
+       for message_format, as described in the docs and
+       as worked previously. (#125759, Richard Hult)
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup):
+       Use g_markup_vprintf_escaped() to escape argumetns.
+
+       * gtk/gtkmessagedialog.[ch]: Add gtk_message_dialog_set_markup()
+       so there is some way to set literal markup.
+
 Wed Oct 29 15:01:32 2003  Owen Taylor  <otaylor@redhat.com>
  
        * gdk/x11/gdkimage-x11.c (_gdk_x11_copy_to_image): Move
index b7b1a4ec2ed77ef87f45bc6e0c38b2afdc84748a..d5fbaef2634f5f3fdd3f84dee1d09f5057fc3e95 100644 (file)
@@ -1,3 +1,16 @@
+Wed Oct 29 15:40:26 2003  Owen Taylor  <otaylor@redhat.com>
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new/
+       gtk_message_dialog_new_with_format): Allow NULL
+       for message_format, as described in the docs and
+       as worked previously. (#125759, Richard Hult)
+
+       * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup):
+       Use g_markup_vprintf_escaped() to escape argumetns.
+
+       * gtk/gtkmessagedialog.[ch]: Add gtk_message_dialog_set_markup()
+       so there is some way to set literal markup.
+
 Wed Oct 29 15:01:32 2003  Owen Taylor  <otaylor@redhat.com>
  
        * gdk/x11/gdkimage-x11.c (_gdk_x11_copy_to_image): Move
index ba9be084181e03982ee140e7ca7d3fc5e5756319..22d1e2ff2a94748351946c45d103487f15ea99ea 100644 (file)
@@ -305,7 +305,6 @@ gtk_message_dialog_new (GtkWindow     *parent,
   va_list args;
 
   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
-  g_return_val_if_fail (message_format != NULL, NULL);
 
   widget = g_object_new (GTK_TYPE_MESSAGE_DIALOG,
                         "message_type", type,
@@ -363,26 +362,25 @@ gtk_message_dialog_new (GtkWindow     *parent,
  * When the user clicks a button a "response" signal is emitted with
  * response IDs from #GtkResponseType. See #GtkDialog for more details.
  *
- * Please note that if you have strings in the printf() arguments
- * passed to this function, you might need to protect against
- * them being interpreted as markup. You can do this using
- * g_markup_escape_text() as in the following example:
+ * Special XML characters in the printf() arguments passed to this
+ * function will automatically be escaped as necessary.
+ * (See g_markup_printf_escaped() for how this is implemented.)
+ * Usually this is what you want, but if you have an existing
+ * Pango markup string that you want to use literally as the
+ * label, then you need to use gtk_message_dialog_set_markup()
+ * instead, since you can't pass the markup string either
+ * as the format (it might contain '%' characters) or as a string
+ * argument.
+ *
  * <informalexample><programlisting>
- *   const gchar *error_text =
- *     "&lt;span weight=\"bold\" size=\"larger\"&gt;"
- *     "Could not open document '%s'."
- *     "&lt;/span&gt;\n\n"
- *     "You do not have appropriate permission to access this file.";
- *   gchar *tmp;
- *   GtkWidget *dialog;
- *   
- *   tmp = g_markup_escape_text (filename, -1);
- *   dialog = gtk_message_dialog_new_with_markup (main_application_window,
- *                                                GTK_DIALOG_DESTROY_WITH_PARENT,
- *                                                GTK_MESSAGE_ERROR,
- *                                                GTK_BUTTONS_CLOSE,
- *                                                error_text, tmp);
- *   g_free (tmp);
+ *  GtkWidget *dialog;
+ *  dialog = gtk_message_dialog_new (main_application_window,
+ *                                   GTK_DIALOG_DESTROY_WITH_PARENT,
+ *                                   GTK_MESSAGE_ERROR,
+ *                                   GTK_BUTTON_CLOSE,
+ *                                   NULL);
+ *  gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog),
+ *                                 markup);
  * </programlisting></informalexample>
  * 
  * Return value: a new #GtkMessageDialog
@@ -402,18 +400,16 @@ gtk_message_dialog_new_with_markup (GtkWindow     *parent,
   va_list args;
 
   g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
-  g_return_val_if_fail (message_format != NULL, NULL);
 
-  widget = gtk_message_dialog_new (parent, flags, type, buttons, "");
+  widget = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
 
   if (message_format)
     {
       va_start (args, message_format);
-      msg = g_strdup_vprintf(message_format, args);
+      msg = g_markup_vprintf_escaped (message_format, args);
       va_end (args);
 
-      gtk_label_set_markup (GTK_LABEL (GTK_MESSAGE_DIALOG (widget)->label),
-                            msg);
+      gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (widget), msg);
 
       g_free (msg);
     }
@@ -421,6 +417,26 @@ gtk_message_dialog_new_with_markup (GtkWindow     *parent,
   return widget;
 }
 
+/**
+ * gtk_message_dialog_set_markup:
+ * @message_dialog: a #GtkMessageDialog
+ * @str: markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>)
+ * 
+ * Sets the text of the message dialog to be @str, which is marked
+ * up with the <link linkend="PangoMarkupFormat">Pango text markup
+ * language</link>.
+ *
+ * Since: 2.4
+ **/
+void
+gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
+                              const gchar      *str)
+{
+  g_return_if_fail (GTK_IS_MESSAGE_DIALOG (message_dialog));
+  
+  gtk_label_set_markup (GTK_LABEL (message_dialog->label), str);
+}
+
 static void
 gtk_message_dialog_add_buttons (GtkMessageDialog* message_dialog,
                                GtkButtonsType buttons)
index d350147722e4ecc86b48559ef7113d18735ba714..fe627c0c3e11ccabb6bd06ab6905c8f3658fc44b 100644 (file)
@@ -98,9 +98,10 @@ GtkWidget* gtk_message_dialog_new_with_markup   (GtkWindow      *parent,
                                                  GtkButtonsType  buttons,
                                                  const gchar    *message_format,
                                                  ...) G_GNUC_PRINTF (5, 6);
 
 
+void       gtk_message_dialog_set_markup  (GtkMessageDialog *message_dialog,
+                                          const gchar      *str);
 
 #ifdef __cplusplus
 }